package cn.shengchao.controler.jssdk;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@CrossOrigin("${project.cross-origin}")
@RequestMapping("/api/${project.version}/wxmp")
@SaIgnore
public class JsSdkController {

    @Autowired
    private WxMpService wxMpService;

    /**
     * 微信JS-SDK获取signature签名以及config配置
     *
     * @param url 页面URL
     */
    @SaIgnore
    @GetMapping("/js-sdk")
    public WxJsapiSignature getSdk(String url) throws WxErrorException {
        return wxMpService.createJsapiSignature(url);
    }
}
